package reflect;

import java.io.File;
import java.lang.reflect.Method;

public class Test2 {
    public static void main(String[] args) throws Exception{
        File dir = new File("./src/reflect");
        File[] files = dir.listFiles(f->f.getName().endsWith(".java"));
        for (File file : files) {
            String substring = file.getName().substring(0, file.getName().indexOf("."));
            Class<?> aClass = Class.forName("reflect." + substring);
            Object o = aClass.newInstance();
            Method[] methods = aClass.getDeclaredMethods();
            for (Method method : methods) {
                if (method.getName().startsWith("s") &&
                method.getParameterCount() == 0){
                    method.invoke(o);
                }
            }
        }
    }
}
